Skip to content

Conversation

Jasonzyt
Copy link

πŸ”— Linked issue

#3511

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Currently, CSV collections don’t behave as described in the documentation.
Instead of allowing each CSV file to contain multiple entries (as the documentation
states), the current implementation treats each CSV file as a single piece of content.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link

vercel bot commented Aug 24, 2025

@Jasonzyt is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

pkg-pr-new bot commented Aug 24, 2025

npm i https://pkg.pr.new/@nuxt/content@3513

commit: f790439

@Jasonzyt Jasonzyt marked this pull request as ready for review August 24, 2025 13:45
@farnabaz
Copy link
Member

Thanks for the PR @Jasonzyt
It shame that I've missed this changes in documentation update. Documentation is wrong.
But this behavior is not planned to support. Instead module could support this behavior only for single file CSV collections.

people: defineCollection({
    type: "data",
    source: "org/people.csv",
    schema: z.object({
      "name": z.string(),
      "email": z.string().email(),
    }),
  }),

It is important to create 1 to 1 and predictable mapping between files in content directory and documents in database. Splitting CSV files outside of collection source login, breaks this predictability.

@Jasonzyt
Copy link
Author

Jasonzyt commented Sep 12, 2025

In my case, I only need single file CSV support.
I agree with you, so documentation should be updated.

My PR can implement single CSV support, but tbh some logic needs to be optimized.
And I think CSV data type support (currently only string) should be added too.

@farnabaz
Copy link
Member

I'll update your PR,
we can test and improve

@farnabaz
Copy link
Member

@Jasonzyt Could you check and test the behavior?
We need to update docs to document both single file and multi file behaviors

src/module.ts Outdated
const { queries, hash } = generateCollectionInsert(collection, parsedContent)
list.push([key, queries, hash])
}
const { queries, hash } = generateCollectionInsert(collection, parsedContent)
Copy link
Author

@Jasonzyt Jasonzyt Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure why you reverted this.
Since CSV files contain multiple rows, and each row should be treated as an independent ParsedContent, they require a special handling process. Each CSV file should not be processed as a single ParsedContent.

In contrast, formats like Markdown/JSON/YML contain only one ParsedContent per file, so they must be handled differently.

And the facts prove this point: after installing the latest package, errors occurred.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSV and other formats must be handled seperately. Maybe we can find a better way to do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to do this, Content now has defineCSVSource which reads csv file and generate a document for each row

@Jasonzyt
Copy link
Author

Jasonzyt commented Sep 12, 2025

And the facts prove this point: after installing the latest package, errors occurred.

In my case

const { data } = await useAsyncData("albumsMeta", () => {
  return queryCollection("albumsMeta").order("updated", "DESC").all();
});

returns

[ { id: 'albumsMeta/albums-meta/albums-meta.csv',                                                                                                                   
    cover: null,
    description: null,
    extension: 'csv',
    meta: { path: '/albums-meta/albums-meta', body: [Array], title: 'Albums Meta' },
    name: null,
    stem: 'albums-meta/albums-meta',
    updated: null,
    urlFormat: null,
    __hash__: 'qZyKG0MlhJb1M0gDHO6L8sGT9FxtlwB_nASlz1K0ooM' } ]

This is exactly the bug mentioned by #3511

@farnabaz
Copy link
Member

@Jasonzyt could you share your reproduction repository? or provide minimal one?

@Jasonzyt
Copy link
Author

Here's my repo: https://github.com/Jasonzyt/gallery

@farnabaz
Copy link
Member

@Jasonzyt There was a mistake in a string, should be good now. Try with https://pkg.pr.new/@nuxt/content@0f6d610

@tazim404
Copy link

tazim404 commented Sep 12, 2025

I installed npm i https://pkg.pr.new/@nuxt/content@3513 and it worked fine. But after few hours when i am installing this package in my different project it give the same error as earlier.

Edit:
And after installing npm i https://pkg.pr.new/@nuxt/content@0f6d610 its giving the same problem

@tazim404
Copy link

Please solve this problem urgently. I have projects to submit

@Jasonzyt
Copy link
Author

@tazim404
Try https://pkg.pr.new/@nuxt/content@c1cefd2 ?
c1cefd2 works for me

but the later changes broke it

@Jasonzyt
Copy link
Author

Jasonzyt commented Sep 13, 2025

@Jasonzyt There was a mistake in a string, should be good now. Try with https://pkg.pr.new/@nuxt/content@0f6d610

@farnabaz Still the same bug behaved like #3511

@farnabaz
Copy link
Member

@Jasonzyt I checked with your projects and it works as expected with single file sources.
Screenshot 2025-09-15 at 11 59 05

try with npm i https://pkg.pr.new/@nuxt/content@f790439

Note: I had to remove styles and some other deps because I was facing issue with oxc in you repo
Note2: It is not recommended to use useAsyncData outside of script setup. this utility is designed to use directly in script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants